﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Farmacia.Entities.Almacen.Laborat;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;

namespace Farmacia.DataAccess.Almacen.Laborat
{
    public class LaboratorioDAO:MasterDAEL,iLaboratorioDAO
    {
        public List<Laboratorio> GetAllFromLaboratorio()
        {
            var query = DataBase.ExecuteSprocAccessor<Laboratorio>("GetAllFromLaboratorio");
            return query.ToList();
        }

        public Laboratorio GetFromLaboratorioById(int id)
        {
            var query = DataBase.ExecuteSprocAccessor<Laboratorio>("GetFromLaboratorioById", id);
            return query.SingleOrDefault(); 
        }

        public void RegistrarLaboratorio(Laboratorio laboratorio)
        {
            DbCommand command = DataBase.GetStoredProcCommand("RegistrarLaboratorio");
            //Para guiarse de que datos o campos van en el agregar
            /*  @ int out,
                @ varchar(350),
                @ varchar(500) = null*/
            DataBase.AddInParameter(command, "idLaboratorio", DbType.Int32, laboratorio.IdLaboratorio);
            DataBase.AddInParameter(command, "nombre", DbType.String, laboratorio.Nombre);
            DataBase.AddInParameter(command, "referencia", DbType.String, laboratorio.Referencia);

            DataBase.ExecuteNonQuery(command);
        }

        public void DeleteLaboratorio(int id)
        {
            DbCommand command = DataBase.GetStoredProcCommand("EliminarLaboratorio");
            DataBase.AddInParameter(command, "idLaboratorio", DbType.Int32, id);
            DataBase.ExecuteNonQuery(command);
        }

        public List<Laboratorio> GetFromLaboratorioByNombre(string nombre)
        {
            var query = DataBase.ExecuteSprocAccessor<Laboratorio>("GetFromLaboratorioByNombre", nombre);
            return query.ToList();

        }
    }
}
